package com.kstech.exccheck.domain.check;


import com.kstech.exccheck.view.check.SingleCheckActivity;

/**
 * ���ʱ�ļ�ʱ�����
 * @author wanghaibin
 * @created 2016-10-23 ����3:23:25
 * @since v1.0
 */
public class CheckTimer {

	private SingleCheckActivity checkActivity;

	public static final String READY = "ready";
	public static final String READY_FINISH = "readyFinish";
	public static final String READY_ERROR = "readyError";
	public static final String START = "start";
	public static final String STOP = "stop";

	private String min = "00";
	private String sec = "00";
	private int totalSec = 0;

	/**
	 * 获取检测时间，用于判断，命令是否超时
	 * @return the totalSec
	 */
	public int getTotalSec() {
		return totalSec;
	}

	public CheckTimer(SingleCheckActivity checkActivity){
		this.checkActivity = checkActivity;
	}

	private Runnable worker = new Runnable() {


		@Override
		public void run() {
			totalSec = totalSec + 1;
			if (totalSec / 60 < 10) {
				min = "0" + totalSec / 60;
			} else {
				sec = "" + totalSec / 60;
			}
			if(totalSec/60>=10){
				min = totalSec/60+"";
			}
			if (totalSec % 60 < 10) {
				sec = "0" + totalSec % 60;
			} else {
				sec = "" + totalSec % 60;
			}
			checkActivity.singleCheckTimeBtn.setText(min + ":" + sec);
			checkActivity.getHandler().postDelayed(this, 1000);

		}
	};


	/**
	 * 启动计时器
	 */
	public void start(){
		checkActivity.getHandler().postDelayed(worker, 1000);
	}

	/**
	 * 停止计时器
	 */
	public void stop(){
		checkActivity.getHandler().removeCallbacks(worker);
		totalSec = 0;
	}

}
